//
//  CSJADLoading.m
//  shortvideoplay
//
//  Created by adam on 2024/7/3.
//

#import "CSJADLoading.h"
#import "AppDelegate.h"
#import "GDTNativeExpressAdView.h"
#import "GDTNativeExpressAd.h"
#import "GDTSplashAd.h"
#import "GDTSDKConfig.h"
#import "GDTUnifiedBannerView.h"
#import "GDTNativeExpressAd.h"
#import "GDTNativeExpressAdView.h"
#import "GDTAdDeleget.h"


@interface CSJADLoading () <BUSplashAdDelegate, BUSplashCardDelegate, BUSplashZoomOutDelegate,BUNativeExpressBannerViewDelegate,BUNativeAdsManagerDelegate, BUNativeAdDelegate,BUNativeExpressAdViewDelegate,GDTUnifiedBannerViewDelegate,DJXAuthorityConfigDelegate>
@property (strong, nonatomic)BUSplashAd * splashAd;
@property (strong, nonatomic)UIButton *custormSkipButton;
@property (strong, nonatomic)BUNativeExpressBannerView *bannerView;
@property (strong, nonatomic)GDTUnifiedBannerView * ylh_bannerView;
@property (nonatomic, strong)BUNativeExpressAdManager *drawAdsManager;
@property (nonatomic, strong) GDTNativeExpressAd *ylh_drawAdsManager;

@end
@implementation CSJADLoading
+ (instancetype)share {
    static CSJADLoading *manager;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[CSJADLoading alloc] init];
    });
    return manager;
}

+(void)initAppYLHAD_successBlock:(void (^)(BOOL issuccess))successBlock{
    NSString *version = [GDTSDKConfig sdkVersion];
    if([GDTSDKConfig initWithAppId:@"1207156630"]){
        [GDTSDKConfig startWithCompletionHandler:^(BOOL success, NSError *error) {
            if(success){
                [CSJADLoading share].isYLHAdInit= NO;
                successBlock(YES);
            }else{
                [CSJADLoading share].isYLHAdInit= NO;
                successBlock(NO);
            }
        }];
    }else{
        [CSJADLoading share].isYLHAdInit= NO;
        successBlock(NO);
    }
}
+(void)initAppCSJAD_successBlock:(void (^)(BOOL issuccess))successBlock{
    BUAdSDKConfiguration *configuration = [BUAdSDKConfiguration configuration];
    configuration.debugLog = @(1);
    // 请更换为在平台申请的appid
    configuration.appID = @"5574056";
       // 如果使用聚合维度功能，则务必将以下字段设置为YES，并检查工程有引用CSJMediation.framework，这样SDK初始化时将启动聚合相关必要组件
       // SDK异步初始化
       [BUAdSDKManager startWithAsyncCompletionHandler:^(BOOL success, NSError *error) {
         if (success) {
           dispatch_async(dispatch_get_main_queue(), ^{
             //请求广告逻辑处理
               NSLog(@"广告初始化成功");
               [CSJADLoading share].isCSJAdInit= YES;
               NSString *configPath = [[NSBundle mainBundle] pathForResource:@"SDK_Setting_5574056" ofType:@"json"];
               DJXConfig *config = [DJXConfig new];
//               config.authorityDelegate = self;
               #if DEBUG
               config.logLevel = DJXSDKLogLevelDebug;
               #endif
               [DJXManager initializeWithConfigPath:configPath config:config];
               [DJXManager startWithCompleteHandler:^(DJXINITStatus initStatus, NSDictionary *userInfo) {
                   if (initStatus == DJXINITStatus_success) {
                       NSLog(@"短剧初始化成功！");
                       if([QZUserInfoModel isLogin]){
                           [self dj_SignWithPaySecretKey];
                       }
                   } else {
                       NSLog(@"短剧初始化失败：%@", userInfo[@"msg"]);
                   }
               }];
               successBlock(YES);
               
           });
         }else{
             dispatch_async(dispatch_get_main_queue(), ^{
               //请求广告逻辑处理
                 successBlock(NO);
                 [CSJADLoading share].isCSJAdInit = NO;
             });
         }
       }];
}
//短剧获取签名参数和登录
+ (void)dj_SignWithPaySecretKey{
    NSString * nonce = @"";//16位随机字符串
    for (int i=0; i<16; i++) {
        int x = arc4random() % 9;
        nonce = [nonce stringByAppendingString:[NSString stringWithFormat:@"%d",x+1]];
    }
    NSString * ouid = [NSString stringWithFormat:@"%@",[QZUserInfoModel share].mid];
    NSString *abc = [DJXManager getSignWithPaySecretKey:@"eaff7c4767a5ee8ffac22cdb9453beb7" nonce:nonce timeStamp:[[NSDate date] timeIntervalSince1970] params:@{@"ouid":ouid}];
    [DJXManager loginWithParamsString:abc completionBlock:^(DJXLoginStatus loginStatus, NSDictionary * _Nonnull userInfo) {
        NSString *type = [[userInfo valueForKey:@"login_type"] isEqualToString:@"guest"] ? @"游客" : @"媒体";
        NSString *status = loginStatus ? @"登录成功" : @"登录失败";
        NSLog(@"%@",[NSString stringWithFormat:@"%@%@", type, status]);
    }];
}
//短剧退出登录
+ (void)dj_SignOutWithPaySecretKey{
    [DJXManager logoutWithCompletionBlock:^(DJXLoginStatus loginStatus, NSDictionary * _Nonnull userInfo) {
        NSString *status = loginStatus ? @"登出成功" : @"登出失败";
        NSLog(@"%@",[NSString stringWithFormat:@"%@", status]);
    }];
}
//短剧推荐列表
+ (void)dj_requestRecommendedPlayletListPage:(NSInteger)page successBlock:(void (^)(NSArray<DJXPlayletInfoModel *> *playletList))successBlock{
    [[DJXPlayletManager shareInstance] requestRecommendedPlayletListPage:page num:10 success:^(NSArray<DJXPlayletInfoModel *> * _Nonnull playletList, NSDictionary<NSString *,NSObject *> * _Nonnull info) {
        successBlock(playletList);
    } failure:^(NSError * _Nonnull error) {
        successBlock(nil);
    }];
//
}
//短剧所有列表
+ (void)dj_requestAllPlayletListPage:(NSInteger)page successBlock:(void (^)(NSArray<DJXPlayletInfoModel *> *playletList))successBlock{
    [[DJXPlayletManager shareInstance] requestAllPlayletListPage:page num:30 order:0 success:^(NSArray<DJXPlayletInfoModel *> * _Nonnull playletList, NSDictionary<NSString *,NSObject *> * _Nonnull info) {
        successBlock(playletList);
    } failure:^(NSError * _Nonnull error) {
        successBlock(nil);
    }];
    
//    DJXPlayletConfig *playletConfig = [DJXPlayletConfig new];
//    playletConfig.playletUnlockADMode = DJXPlayletUnlockADMode_Common;
//    playletConfig.freeEpisodesCount = 10;
//    playletConfig.unlockEpisodesCountUsingAD = 5;
//    playletConfig.playerDelegate = self;

//    config.playletConfig = playletConfig;
//    config.drawVCTabOptions = DJXDrawVideoVCTabOptions_theater | DJXDrawVideoVCTabOptions_playlet_feed;
//    config.viewSize = CGSizeMake(LCSScreenWidth, LCSScreenHeight);
//    config.delegate = self;
//
}
//短剧请求所有接口
//- (void)requestAll {
//    [[DJXPlayletManager shareInstance] requestAllPlayletListWithOrder:[self.orderTf.text integerValue] success:^(NSArray<DJXPlayletInfoModel *> * _Nonnull playletList, NSDictionary<NSString *,NSObject *> * _Nonnull info) {
//        NSMutableString *str = [NSMutableString string];
//        for (DJXPlayletInfoModel *model in playletList) {
//            [str appendString: [model performSelector:@selector(BUYY_modelToJSONString)]];
//            [str appendString:@"/*/"];
//        }
//        [self.responseBtn1 setTitle:str forState:UIControlStateNormal];
//        self.dataArray1 = playletList;
//    } failure:^(NSError * _Nonnull error) {
//        NSString *failString = [NSString stringWithFormat:@"code:%@ msg:%@", @(error.code), error.localizedDescription];
//        [self.responseBtn1 setTitle:failString forState:UIControlStateNormal];
//    }];
//}
//
//- (void)requsetHistory {
//    [[DJXPlayletManager shareInstance] requestPlayletHistoryListWithPage:self.pageTf.text.integerValue num:self.numTf.text.integerValue success:^(NSArray<DJXPlayletInfoModel *> * _Nonnull playletList) {
//        NSMutableString *str = [NSMutableString string];
//        for (DJXPlayletInfoModel *model in playletList) {
//            [str appendString: [model performSelector:@selector(BUYY_modelToJSONString)]];
//            [str appendString:@"/*/"];
//        }
//        [self.histortResultBtn setTitle:str forState:UIControlStateNormal];
//        NSLog(@"[短剧回调]历史记录 %@",str);
//    } failure:^(NSError * _Nonnull error) {
//        NSString *failString = [NSString stringWithFormat:@"code:%@ msg:%@", @(error.code), error.localizedDescription];
//        [self.histortResultBtn setTitle:failString forState:UIControlStateNormal];
//        NSLog(@"[短剧回调]历史记录 %@",failString);
//    }];
//}
//
//- (void)cleanHistory {
//    [[DJXPlayletManager shareInstance] requestPlayletHistoryCleanWithCompletion:^{
//        NSString *str = @"成功";
//        NSLog(@"[短剧回调]历史记录清除%@",str);
//    } failure:^(NSError * _Nonnull error) {
//        NSString *failString = [NSString stringWithFormat:@"失败 code:%@ msg:%@", @(error.code), error.localizedDescription];
//        NSLog(@"[短剧回调]历史记录清除%@",failString);
//    }];
//}
////短剧分类列表
//- (void)requestPlayletCategoryList {
//    [[DJXPlayletManager shareInstance] requestCategoryList:^(NSArray<NSString *> * _Nonnull categoryList) {
//        [categoryList enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
//            NSLog(@"[短剧回调]短剧分类 %2lu: %@", idx, obj);
//        }];
//    } failure:^(NSError * _Nonnull error) {
//        NSString *failString = [NSString stringWithFormat:@"失败 code:%@ msg:%@", @(error.code), error.localizedDescription];
//        NSLog(@"[短剧回调]短剧分类%@",failString);
//    }];
//}
//
//- (void)requestWithCategory {
//    [[DJXPlayletManager shareInstance] requestCategoryPlayletLisWithCategory:self.categoryTf.text page:1 num:100 success:^(NSArray<DJXPlayletInfoModel *> * _Nonnull playletList) {
//        NSMutableString *str = [NSMutableString string];
//        for (DJXPlayletInfoModel *model in playletList) {
//            [str appendString: [model performSelector:@selector(BUYY_modelToJSONString)]];
//            [str appendString:@"/*/"];
//        }
//        [self.categoryRespBtn2 setTitle:str forState:UIControlStateNormal];
//    } failure:^(NSError * _Nonnull error) {
//        NSString *failString = [NSString stringWithFormat:@"失败 code:%@ msg:%@", @(error.code), error.localizedDescription];
//        [self.categoryRespBtn2 setTitle:failString forState:UIControlStateNormal];
//    }];
//}
//
//- (void)requestWithSearchWord {
//    [[DJXPlayletManager shareInstance] requestCategoryPlayletLisWithSearchWord:self.searchTf.text isFuzzy:false page:1 num:100 success:^(NSArray<DJXPlayletInfoModel *> * _Nonnull playletList, BOOL hasMore) {
//        NSMutableString *str = [NSMutableString string];
//        for (DJXPlayletInfoModel *model in playletList) {
//            [str appendString: [model performSelector:@selector(BUYY_modelToJSONString)]];
//            [str appendString:@"/*/"];
//        }
//        [self.searchRespBtn2 setTitle:str forState:UIControlStateNormal];
//    } failure:^(NSError * _Nonnull error) {
//        NSString *failString = [NSString stringWithFormat:@"失败 code:%@ msg:%@", @(error.code), error.localizedDescription];
//        [self.searchRespBtn2 setTitle:failString forState:UIControlStateNormal];
//    }];
//}



+ (void)ADSplashAdRequest{
//    [CSJADLoading share].splashAd = [[BUSplashAd alloc] initWithSlotID:@"889521324" adSize:CGSizeMake(KScreen_W, KScreen_H)];
    [CSJADLoading share].splashAd = [[BUSplashAd alloc] initWithSlotID:@"889521826" adSize:CGSizeMake(KScreen_W, KScreen_H)];
//    [CSJADLoading share].splashAd.supportCardView = YES;
//    [CSJADLoading share].splashAd.supportZoomOutView = YES;
//    [CSJADLoading share].splashAd.hideSkipButton = YES;
    [CSJADLoading share].splashAd.tolerateTimeout = 3;
    [CSJADLoading share].splashAd.delegate = [CSJADLoading share];
    [CSJADLoading share].splashAd.cardDelegate = [CSJADLoading share];
    [CSJADLoading share].splashAd.zoomOutDelegate = [CSJADLoading share];
    [[CSJADLoading share].splashAd loadAdData];
}
+ (void)ADBannerAdRequest:(DS_FatherVC *)viewController{
    [QZUserInfoModel adRequestType:^(NSInteger type) {
        if(type == 0){
            [CSJADLoading share].bannerView = [[BUNativeExpressBannerView alloc] initWithSlotID:@"958914164" rootViewController:viewController adSize:CGSizeMake(KScreen_W, 45) interval:30]; // 聚合维度通过广告位ID发起请求；仅接入CSJ广告通过代码位ID发起请求
            [CSJADLoading share].bannerView.backgroundColor = [UIColor clearColor];
            [CSJADLoading share].bannerView.frame = CGRectMake(0, 0, KScreen_W, 45);
            [CSJADLoading share].bannerView.delegate = [CSJADLoading share];
            [[CSJADLoading share].bannerView loadAdData];
        }else{
            [CSJADLoading share].ylh_bannerView = [[GDTUnifiedBannerView alloc] initWithFrame:CGRectMake(0, 0, KScreen_W, 45) placementId:@"3161532821315983" viewController:viewController]; // 聚合维度通过广告位ID发起请求；仅接入CSJ广告通过代码位ID发起请求
            [CSJADLoading share].ylh_bannerView.autoSwitchInterval = 30;
            [CSJADLoading share].ylh_bannerView.delegate = [CSJADLoading share];
            [[CSJADLoading share].ylh_bannerView loadAdAndShow];
        }
    }];
   

}
+ (void)ADNativeAdsAdRequest:(NSInteger)count{
    [QZUserInfoModel adRequestType:^(NSInteger type) {
        if(type == 0){
            BUAdSlot *adSlot = [[BUAdSlot alloc] init];
            adSlot.ID = @"958914160";
            adSlot.AdType = BUAdSlotAdTypeDrawVideo; //required
            adSlot.position = BUAdSlotPositionTop;
            adSlot.imgSize = [BUSize sizeBy:BUProposalSize_DrawFullScreen];
            [CSJADLoading share].drawAdsManager = [[BUNativeExpressAdManager alloc] initWithSlot:adSlot adSize:CGSizeMake(KScreen_W, KScreen_H-KTab_H)];
            // 配置：回调代理对象
            [CSJADLoading share].drawAdsManager.delegate = [CSJADLoading share];
            [[CSJADLoading share].drawAdsManager loadAdDataWithCount:count];
        }else{
            [CSJADLoading share].ylh_drawAdsManager = [[GDTNativeExpressAd alloc] initWithPlacementId:@"" adSize:CGSizeMake(KScreen_W, KScreen_H-KTab_H)];
            [CSJADLoading share].ylh_drawAdsManager.delegate = [GDTAdDeleget share];
              // 配置视频播放属性
            [CSJADLoading share].ylh_drawAdsManager.videoAutoPlayOnWWAN = YES;
            [[CSJADLoading share].ylh_drawAdsManager loadAd:count];
        }
    }];
    
}
+ (void)ADNativeAdsAdPhoneRequest:(NSInteger)count{
    [QZUserInfoModel adRequestType:^(NSInteger type) {
        CGFloat w = (KScreen_W-3)/2;
        if(type == 0){
            BUAdSlot *adSlot = [[BUAdSlot alloc] init];
            adSlot.ID = @"959027546";
            adSlot.AdType = BUAdSlotAdTypeFeed; //required
            adSlot.position = BUAdSlotPositionFeed;
            adSlot.imgSize = [BUSize sizeBy:BUProposalSize_DrawFullScreen];
            [CSJADLoading share].drawAdsManager = [[BUNativeExpressAdManager alloc] initWithSlot:adSlot adSize:CGSizeMake(w, w)];
            // 配置：回调代理对象
            [CSJADLoading share].drawAdsManager.delegate = [CSJADLoading share];
            [[CSJADLoading share].drawAdsManager loadAdDataWithCount:count];
        }else{
            [CSJADLoading share].ylh_drawAdsManager = [[GDTNativeExpressAd alloc] initWithPlacementId:@"5141034871210899" adSize:CGSizeMake(w, w)];
            [CSJADLoading share].ylh_drawAdsManager.delegate = [GDTAdDeleget share];
              // 配置视频播放属性
            [CSJADLoading share].ylh_drawAdsManager.videoAutoPlayOnWWAN = YES;
            [[CSJADLoading share].ylh_drawAdsManager loadAd:count];
        }
    }];
    
}


#pragma mark BUMNativeExpressBannerViewDelegate
- (void)nativeExpressBannerAdViewDidLoad:(BUNativeExpressBannerView *)bannerAdView{
    NSLog(@"");
}
- (void)nativeExpressBannerAdView:(BUNativeExpressBannerView *)bannerAdView didLoadFailWithError:(NSError *_Nullable)error{
    self.BannerAdsLoadFish(nil);
    NSLog(@"");
}
- (void)nativeExpressBannerAdViewRenderSuccess:(BUNativeExpressBannerView *)bannerAdView {
 //在此回调方法中进行广告的展示，可保证播放流畅和展示流畅，用户体验更好。
    bannerAdView.backgroundColor = UIColor.whiteColor;
    self.BannerAdsLoadFish(bannerAdView);
//    [self.adBgView removeAllSubviews];
//    [self.adBgView addSubview:bannerAdView];
//    [bannerAdView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.edges.equalTo(self.adBgView);
//    }];
//    bannerAdView.backgroundColor = [UIColor clearColor];
//    self.adbgHeight.constant = 90;
//    if(!self.tomid){
//        self.adbgBttom.constant = self.adbgBttom.constant+59;
//    }
//    [UIView animateWithDuration:0.3 animations:^{
//        [self.view layoutIfNeeded];
//    }];
//    bannerAdView.translatesAutoresizingMaskIntoConstraints = NO;
}
- (void)nativeExpressBannerAdViewRenderFail:(BUNativeExpressBannerView *)bannerAdView error:(NSError *)error {
    NSLog(@"nativeExpressBannerAdViewRenderFail");
}
#pragma mark ylh banner代理
- (void)unifiedBannerViewFailedToLoad:(GDTUnifiedBannerView *)unifiedBannerView error:(NSError *)error
{
    self.BannerAdsLoadFish(nil);
}
- (void)unifiedBannerViewDidLoad:(GDTUnifiedBannerView *)unifiedBannerView{
    self.BannerAdsLoadFish(unifiedBannerView);
    NSLog(@"===banner奖励：%ld",[unifiedBannerView eCPM]);
}
#pragma mark splashAD
- (void)splashAdLoadSuccess:(nonnull BUSplashAd *)splashAd {
    [SVProgressHUDTool dismiss];
    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
    [splashAd showSplashViewInRootViewController:app.window.rootViewController];
    if (splashAd.hideSkipButton) { // 自定义跳过按钮
        [splashAd.splashView addSubview:self.custormSkipButton];
    }
}
// 自定义跳过按钮
- (UIButton *)custormSkipButton {
    if(_custormSkipButton == nil){
        _custormSkipButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_custormSkipButton setTitle:@"关闭" forState:UIControlStateNormal];
        [_custormSkipButton setTitleColor:[UIColor darkTextColor] forState:UIControlStateNormal];
        [_custormSkipButton addTarget:self action:@selector(skipButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
        CGFloat safeBottomMargin = 12.0;
        _custormSkipButton.frame = CGRectMake(KScreen_W - 56 - 12, kStatusBarHeight+6, 50, 30);
        _custormSkipButton.userInteractionEnabled = NO;
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            self->_custormSkipButton.userInteractionEnabled = YES;
        });
    }
    return _custormSkipButton;
}
- (void)skipButtonTapped:(UIButton *)sender {
   [_splashAd removeSplashView];
    if(self.SplashAdLoadFish){
        self.SplashAdLoadFish(YES);
    }else{
        [self fishBolck:YES];
    }
}
- (void)splashAdLoadFail:(nonnull BUSplashAd *)splashAd error:(BUAdError * _Nullable)error {
    [self pbu_logWithSEL:_cmd msg:@""];
    if(self.SplashAdLoadFish){
        self.SplashAdLoadFish(NO);
    }else{
        [self fishBolck:NO];
    }
}

- (void)splashAdRenderFail:(nonnull BUSplashAd *)splashAd error:(BUAdError * _Nullable)error {
    [self pbu_logWithSEL:_cmd msg:@""];
    if(self.SplashAdLoadFish){
        self.SplashAdLoadFish(NO);
    }else{
        [self fishBolck:NO];
    }
}


- (void)splashAdRenderSuccess:(nonnull BUSplashAd *)splashAd {
    [self pbu_logWithSEL:_cmd msg:@""];
}

- (void)splashAdWillShow:(nonnull BUSplashAd *)splashAd {
    [self pbu_logWithSEL:_cmd msg:@""];
}

- (void)splashAdDidShow:(nonnull BUSplashAd *)splashAd {
    [self pbu_logWithSEL:_cmd msg:@""];
}

- (void)splashAdDidClick:(nonnull BUSplashAd *)splashAd {
    [self pbu_logWithSEL:_cmd msg:@""];
}

- (void)splashAdDidClose:(nonnull BUSplashAd *)splashAd closeType:(BUSplashAdCloseType)closeType {
    [_splashAd removeSplashView];
    if(self.SplashAdLoadFish){
        self.SplashAdLoadFish(YES);
    }else{
        [self fishBolck:YES];
    }
}

- (void)splashCardReadyToShow:(nonnull BUSplashAd *)splashAd {
    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
    [splashAd showCardViewInRootViewController:app.window.rootViewController];
    
    [self pbu_logWithSEL:_cmd msg:@""];
}

- (void)splashCardViewDidClick:(nonnull BUSplashAd *)splashAd {
    [self pbu_logWithSEL:_cmd msg:@""];
}

- (void)splashCardViewDidClose:(nonnull BUSplashAd *)splashAd {
    [self pbu_logWithSEL:_cmd msg:@""];
}

- (void)splashAdViewControllerDidClose:(BUSplashAd *)splashAd {
    [self pbu_logWithSEL:_cmd msg:@""];
}

- (void)splashDidCloseOtherController:(nonnull BUSplashAd *)splashAd interactionType:(BUInteractionType)interactionType {
    [self pbu_logWithSEL:_cmd msg:@""];
}


- (void)splashVideoAdDidPlayFinish:(nonnull BUSplashAd *)splashAd didFailWithError:(nullable NSError *)error {
    [self pbu_logWithSEL:_cmd msg:@""];
}


- (void)splashZoomOutViewDidClick:(nonnull BUSplashAd *)splashAd {
    [self pbu_logWithSEL:_cmd msg:@""];
}


- (void)splashZoomOutViewDidClose:(nonnull BUSplashAd *)splashAd {
    [self pbu_logWithSEL:_cmd msg:@""];
}

- (void)splashZoomOutReadyToShow:(nonnull BUSplashAd *)splashAd {
    
    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
    
    // 接入方法一：使用SDK提供动画接入
    if (splashAd.zoomOutView) {
        [splashAd showZoomOutViewInRootViewController:app.window.rootViewController];
    }
    [self pbu_logWithSEL:_cmd msg:@""];
}


- (void)pbu_logWithSEL:(SEL)sel msg:(NSString *)msg {
}
- (void)fishBolck:(BOOL)isFish{
    KWeakSelf
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        if(weakSelf.SplashAdLoadFish){
            weakSelf.SplashAdLoadFish(isFish);
        }else{
            [weakSelf fishBolck:isFish];
        }
    });
}
#pragma mark - BUNativeExpressAdViewDelegate
- (void)nativeExpressAdSuccessToLoad:(BUNativeExpressAdManager *)nativeExpressAd views:(NSArray<__kindof BUNativeExpressAdView *> *)views {
    if(self.ADNativeAdsLoadFish){
        self.ADNativeAdsLoadFish(views,0);
    }
    NSLog(@"开始结束");
}

- (void)nativeExpressAdFailToLoad:(BUNativeExpressAdManager *)nativeExpressAd error:(NSError *)error {
    if(self.ADNativeAdsLoadFish){
        self.ADNativeAdsLoadFish(nil,0);
    }
}

- (void)nativeExpressAdViewRenderSuccess:(BUNativeExpressAdView *)nativeExpressAdView {
//    [self.tableView reloadData];
    NSLog(@"====== %p videoDuration = %ld",nativeExpressAdView,(long)nativeExpressAdView.videoDuration);

}

- (void)nativeExpressAdView:(BUNativeExpressAdView *)nativeExpressAdView stateDidChanged:(BUPlayerPlayState)playerState{
//    BUPlayerStateFailed    = 0,
//    BUPlayerStateBuffering = 1,
//    BUPlayerStatePlaying   = 2,
//    BUPlayerStateStopped   = 3,
//    BUPlayerStatePause     = 4,
//    BUPlayerStateDefalt    = 5
    if(playerState == BUPlayerStatePlaying){
        NSLog(@"广告播放开始");
        if(![[QZUserInfoModel share].adSaveFishArr containsObject:[QZUserInfoModel share].adPlayId]){
            [[QZHongBaoView share] stopClick:YES];
        }
    }else{
        NSLog(@"广告播放结束%f===%ld",nativeExpressAdView.currentPlayedTime,(long)nativeExpressAdView.videoDuration);
        [[QZHongBaoView share] stopClick:NO];
        if(nativeExpressAdView.videoDuration - nativeExpressAdView.currentPlayedTime < 1 ){
            if(![[QZUserInfoModel share].adSaveFishArr containsObject:[QZUserInfoModel share].adPlayId]){
                [[QZUserInfoModel share].adSaveFishArr addObject:[QZUserInfoModel share].adPlayId];
                
            }
            if(self.ADNativeAdsLoadPlayFish){
                self.ADNativeAdsLoadPlayFish(YES);
            }
        }
    }
}
- (void)nativeAdVideoDidPlayFinish:(BUNativeAd *)nativeAd{
    NSLog(@"广告播放完成");
}
- (void)nativeAdVideo:(BUNativeAd *_Nullable)nativeAdView rewardDidCountDown:(NSInteger)countDown{
    NSLog(@"广告奖励将发放");
}

- (void)nativeExpressAdViewRenderFail:(BUNativeExpressAdView *)nativeExpressAdView error:(NSError *)error {
    
}

- (void)nativeExpressAdViewWillShow:(BUNativeExpressAdView *)nativeExpressAdView {

}

- (void)nativeExpressAdViewDidClick:(BUNativeExpressAdView *)nativeExpressAdView {

}

- (void)nativeExpressAdViewPlayerDidPlayFinish:(BUNativeExpressAdView *)nativeExpressAdView error:(NSError *)error {

}

- (void)nativeExpressAdView:(BUNativeExpressAdView *)nativeExpressAdView dislikeWithReason:(NSArray<BUDislikeWords *> *)filterWords {

}

- (void)nativeExpressAdViewDidClosed:(BUNativeExpressAdView *)nativeExpressAdView {
  
}

- (void)nativeExpressAdViewWillPresentScreen:(BUNativeExpressAdView *)nativeExpressAdView {

}

- (void)nativeExpressAdViewDidCloseOtherController:(BUNativeExpressAdView *)nativeExpressAdView interactionType:(BUInteractionType)interactionType {
    NSString *str;
    if (interactionType == BUInteractionTypePage) {
        str = @"ladingpage";
    } else if (interactionType == BUInteractionTypeVideoAdDetail) {
        str = @"videoDetail";
    } else {
        str = @"appstoreInApp";
    }
}
@end
